package com.sanfeng.smbms.controller;


import com.sanfeng.smbms.common.utils.PageUtils;
import com.sanfeng.smbms.common.utils.R;
import com.sanfeng.smbms.entity.CustomerEntity;
import com.sanfeng.smbms.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * @author Nelson
 * @email Nelson@gmail.com
 * 客户信息
 * @date 2022-07-03 17:23:56
 */
@RestController
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = customerService.queryPage(params);
        return R.ok().put("page", page);
    }

    @RequestMapping(value = "/listAll", method = RequestMethod.GET)
    public R listAll() {
        List<CustomerEntity> customerEntities = customerService.queryPage();
        return R.ok().put("page", customerEntities);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{customerid}")
    public R info(@PathVariable("customerid") Integer customerid) {
        CustomerEntity customer = customerService.getById(customerid);
        return R.ok().put("customer", customer);
    }

    /**
     * 保存
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public R save(@RequestBody CustomerEntity customer) {
        customerService.save(customer);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CustomerEntity customer) {
        customerService.updateById(customer);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody List customerids) {
        customerService.removeByIds(customerids);
        return R.ok();
    }

}
